inp = window.Input
inp.createKey "left",  ["A", "LEFT"]
inp.createKey "right", ["D", "RIGHT"]
inp.createKey "up",    ["W", "UP"]
inp.createKey "down",  ["S", "DOWN"]
inp.createKey "run",   ["SHIFT"]
inp.createKey "pickup",   ["SPACE"]
inp.createKey "hurl",   ["SPACE"]

inp.createKey "movement",  ["A", "LEFT", 
                            "D", "RIGHT", 
                            "W", "DOWN", 
                            "S", "RIGHT"]

ctx = new window.Context "main", 800, 400
ctx.clearColor 0.0, 0.0, 0.0, 1.0

currentScreen = null

window.makeCurrentScreen = (screen) ->
  console.log screen
  screen.setLast currentScreen
  currentScreen = screen 

window.onload = ->
  run = () ->
    currentScreen.update()
    currentScreen.render()

  g = new window.Game(ctx)
  p = g.load()
  p.then () ->
    window.makeCurrentScreen g
    setInterval run, 16
  